        var backTop = document.getElementById("backTop"),
        topH,//滚动条距离顶部高度
        backTopSpeed,//滚动速度
        backTopTimer;//定时器
    backTop.addEventListener('click', function () {
        var backTopTimer = setInterval(function () {
            topH = document.documentElement.scrollTop || document.body.scrollTop;
            backTopSpeed = Math.floor(-topH / 8);//取整
            if (topH > 0) {
                document.documentElement.scrollTop = document.body.scrollTop = topH + backTopSpeed;
            } else {
                clearInterval(backTopTimer);
            }
        }, 30);
    });
    var backTopTimer = setInterval(function () {
        topH = document.documentElement.scrollTop || document.body.scrollTop;
        backTopSpeed = Math.floor(-topH / 8);//取整
        if (topH > 2) {
            gotop.style.display = "block";
        } else {
            gotop.style.display = "none";
        }
    })

////点击商品打开商品详情

    var nn = localStorage.getItem("name");
    var such = document.getElementById("such")
        console.log(nn);
    var classcar = document.getElementById("classcar")
    classcar.onclick=function(){
        window.location.href="/User/myCarPage"
    }

//////点击轮播图跳转到商品详情页
$(document).ready(function() {
    var gid = localStorage.getItem("gg")
    console.log(gid)
    if(gid===144||gid===131||gid===132) {
        $.ajax({
            type: 'get',
            data: {
                goodsId: gid,
            },
            url: "/client/findGoodsBygoodsId",
            success: function (data) {
                console.log(data);
                console.log(data.t.goodsBrand)
                var goodsid = data.t.goodsId;
                var shopid = data.t.shopId;
                var count = data.t.goodsPrice;
                console.log(goodsid);
                console.log(shopid);
                console.log(count);
                localStorage.setItem("goodsid", goodsid)
                localStorage.setItem("shopid", shopid)
                localStorage.setItem("count", count)
                document.getElementById("such").innerHTML += `
            <div class="good" name="${data.t.goodsId}"><img src="${data.t.goodsImg}" class="photo"></div>
            <h3 class="name" name="${data.t.shopId}">${data.t.goodsName}</h3>
            <h2 class="price">${data.t.goodsPrice}</h2>
            `
            },

            error: function () {
                console.log(data)
            }
        })

    }else{
        $(document).ready(function () {
            $.ajax({
                type: 'get',
                data: {
                    goodsId: nn,
                },
                url: "/client/findGoodsBygoodsId",
                success: function (data) {
                    console.log(data);
                    console.log(data.t.goodsBrand)
                    var goodsid = data.t.goodsId;
                    var shopid = data.t.shopId;
                    var count = data.t.goodsPrice;
                    console.log(goodsid);
                    console.log(shopid);
                    console.log(count);
                    localStorage.setItem("goodsid", goodsid)
                    localStorage.setItem("shopid", shopid)
                    localStorage.setItem("count", count)
                    document.getElementById("such").innerHTML += `
            <div class="good" name="${data.t.goodsId}"><img src="${data.t.goodsImg}" class="photo"></div>
            <h3 class="name" name="${data.t.shopId}">${data.t.goodsName}</h3>
            <h2 class="price">${data.t.goodsPrice}</h2>
            `
                },
                error: function () {
                    console.log(error);
                }
            })
        })
        var classcar = document.getElementById("classcar")
        classcar.onclick = function () {
            window.location.href = "/User/myCarPage"
        }
    }

})


/////点击加减号改变input框里的值
var sub = document.getElementById("sub")
var add = document.getElementById("add")
var numb = document.getElementById("numb")
$("#add").click(function() {
    var num = parseInt($("#numb").val()) || 0;
    $("#numb").val(num + 1);

})
$("#sub").click(function() {
    var num = parseInt($("#numb").val()) || 0;
    num = num - 1;
    num = num < 1 ? 1 : num;
    $("#numb").val(num);
})
////立即购买
var buy = document.getElementById("buy")
buy.onclick = function(){

}
//////加入购物车
var addcar = document.getElementById("addcar")
var name_1 = document.querySelector(".name")
var addre = document.querySelector(".address")
console.log(name_1)
console.log(addre)
addcar.onclick = function(){
    var gsd = localStorage.getItem("goodsid")
    var shd = localStorage.getItem("shopid")
    var ccc = localStorage.getItem("count")
    var id = name_1.innerHTML;
    var count = numb.value;
    console.log(id)
    console.log(gsd)
    console.log(shd)
    console.log(ccc)
    $.ajax({
        type:'post',
        data:{
            goodsCount:count,
            goodsId:gsd,
            shopId:shd,
            userId:id,
        },
        url:"/cart/addGoods",
        success:function (data) {
            console.log(data);
            console.log(count)
            alert("添加成功")
        },
        error:function(){
            alert("添加失败")
        }
    })
}
//////立即购买生成订单
var buy = document.getElementById("buy")
buy.onclick = function () {
    var fg = localStorage.getItem("key");
    console.log(fg)
    if (fg == 0) {
        alert("您还没有登录，请您先登录！")
        window.location.href = "User/login";
    } else {
        var mymessage = confirm("你点击了立即购买，请问是否立即下单？")
        if (mymessage == true) {
            var gsd = localStorage.getItem("goodsid")
            var shd = localStorage.getItem("shopid")
            var ccc = localStorage.getItem("count")
            var id = name_1.innerHTML;
            var address = addre.innerHTML;
            var count = numb.value;
            var price = ccc * count
            console.log(id)
            console.log(gsd)
            console.log(shd)
            console.log(ccc)
            $.ajax({
                type: 'post',
                data: {
                    addressId: address,
                    goodsCount: count,
                    goodsId: gsd,
                    goodsPrice: price,
                    shopId: shd,
                    userId: id,
                },
                url: "/Order/addOrderInPage",
                success: function (data) {
                    console.log(data)
                    console.log(count)
                    console.log(price)
                    alert("已生成订单")
                    ////////立即支付
                    // $.ajax({
                    //     type:'get',
                    //     data:{
                    //
                    //     },
                    //     url:"/Pay/alipay"
                    // })

                },
                error: function () {
                    alert("订单生成失败")
                }
            })
        } else if (mymessage == false) {
            alert("您已取消购买")
            return false;

        }
    }
}
    // 点击添加到喜欢按钮
    var addlike=document.querySelector("#addlike");
    // var addlike = document.getElementById("addlike");
    console.log(addlike);
    addlike.onclick = function () {
        var fg = localStorage.getItem("key");
        console.log(fg)
        if (fg == 0) {
            alert("您还没有登录，请您先登录！")
            window.location.href = "User/login";
        } else {
            var gsd = localStorage.getItem("goodsid")
            var shd = localStorage.getItem("shopid")
            var id = name_1.innerHTML;
            var count = numb.value;
            console.log(id)
            console.log(gsd)
            console.log(shd)
            $.ajax({
                type: 'post',
                data: {
                    goodsId: gsd,
                    shopId: shd,
                    userId: id
                },
                url: "/Like/addUserLike",
                success: function (data) {
                    console.log(data);
                    alert("加入购物车成功！")
                    localStorage.setItem("gsd", gsd)
                },
                error: function () {
                    alert("加入失败！")
                }
            })
        }
    }
        var top1 = document.getElementById("top1")
        var top2 = document.getElementById("top2")
        var top3 = document.getElementById("top3")
        var top4 = document.getElementById("top4")
        top1.onclick=function () {
            var fg = localStorage.getItem("key");
            console.log(fg)
            if(fg==0){
                alert("您还没有登录，请您先登录！")
                window.location.href = "User/login";
            }else if(fg==2){
                window.location.href="/admin/login";
            }else if(fg==3){
                alert("管理员正在审核，请耐心等待！")
            }else if(fg==4){
                window.location.href="/Merchant/personShopCar"
            }else if(fg==1){
                var r=confirm("是否申请成为商家？");
                if (r==true) {
                    content.style.display = "none";
                    mone.style.display = "block";
                }else{
                    window.location.href="/goodsDetail"
                }
            }
        }
        top2.onclick=function(){
            var fg = localStorage.getItem("key");
            console.log(fg)
            if(fg==0){
                alert("你还没有登录，请你先登录")
                window.location.href = "User/login";
            }else{
                window.location.href="/User/userInterface"
            }
        }
        top3.onclick=function () {
            window.location.href="/User/myCarPage"
        }
        top4.onclick=function(){
            window.location.href="/"
        }
